package com.kevin.minio.util;

import com.google.common.collect.Maps;
import com.kevin.minio.config.MinioConfiguration;

import java.util.Map;
import java.util.Optional;

/**
 * @author Kevin Liu
 * @date 2020/6/9 7:19 下午
 */
public class FileUploadClientFactory {

    private final MinioConfiguration configuration;

    private final Map<String, FileUploadClient> clients = Maps.newHashMap();

    public FileUploadClientFactory(MinioConfiguration configuration) {
        this.configuration = configuration;
    }

    public FileUploadClient openFileUploadClient(String bucketName){
       return Optional.ofNullable(clients.get(bucketName)).orElseGet(()->{
            FileUploadClient fileUploadClient = new FileUploadClient(configuration.openClient(), bucketName);
            clients.put(bucketName,fileUploadClient);
            return fileUploadClient;
        });
    }


}
